package com.fdb.efp.esb.service.impl.hj;

import com.fdb.efp.esb.common.client.resp.EsbRespServiceBean;
import com.fdb.efp.esb.common.constant.ESBClientConstance;
import com.fdb.efp.esb.common.constant.EsbBizEnums;
import com.fdb.basic.framework.core.constant.ESBConstant;
import com.fdb.basic.framework.core.exception.BizException;
import com.fdb.efp.esb.service.bo.req.hj.RepAccLoanDetailsQueryBean;
import com.fdb.efp.esb.service.bo.resp.hj.RespAccLoanDetailsQueryBean;
import com.fdb.efp.esb.service.client.ESBRequestBuilder;
import com.fdb.efp.esb.service.client.EsbBaseBean;
import com.fdb.efp.esb.service.facade.hj.AccLoanDetailsQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import static com.fdb.basic.framework.core.constant.ESBConstant.SCENE_NO_07;
import static com.fdb.basic.framework.core.constant.ESBConstant.TRADE_CODE_30230006;

/**
 * 需求编号:2020D05--
 * 问题编号:
 * 开发人员: wengqw
 * 创建日期:2020/11/12
 * 功能描述:
 * 修改日期:2020/11/12
 * 修改描述:
 */
@Service("accLoanDetailsQueryService")
public class AccLoanDetailsQueryServiceImpl implements AccLoanDetailsQueryService {

    Logger logger = LoggerFactory.getLogger(AccLoanDetailsQueryServiceImpl.class);

    @Override
    public RespAccLoanDetailsQueryBean loanDetailsQuery(RepAccLoanDetailsQueryBean repAccLoanDetailsQueryBean, String glblSrlNo) {
        RespAccLoanDetailsQueryBean respAccLoanDetailsQueryBean = null;
        logger.info("======>调用客户借据明细查询接口【" + glblSrlNo + "_30230006_07】开始<======");
        String retMsg = "";
        try {
            EsbBaseBean esbBaseBean = EsbBaseBean.EsbBaseBeanBuilder.
                    anEsbBaseBean().
                    withINSTID(ESBClientConstance.bdInstId).withGLBLSRLNO(glblSrlNo).build();

            EsbRespServiceBean recvBean = ESBRequestBuilder.buildClient().
                    withEsbBaseBean(esbBaseBean)
                    .withBody(repAccLoanDetailsQueryBean)
                    .withTradeNo(TRADE_CODE_30230006)
                    .withScene(ESBConstant.SCENE_NO_07)
                    .create()
                    .sendAndReceive();
            String retCd = recvBean.getSysHead().getRetInfArry().get(0).getRetCd();
            retMsg = recvBean.getSysHead().getRetInfArry().get(0).getRetMsg();
            if (EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(retCd)) {
                respAccLoanDetailsQueryBean = recvBean.getBody(RespAccLoanDetailsQueryBean.class);
            }
            if (null != respAccLoanDetailsQueryBean) {
                if (null != respAccLoanDetailsQueryBean.getDbllArry()) {
                    if (respAccLoanDetailsQueryBean.getDbllArry().size() > 0) {
                        logger.info("客户号：" + repAccLoanDetailsQueryBean.getCustAcctNo() + "借据明细信息查询成功");
                    }
                } else {
                    logger.info("客户号：" + repAccLoanDetailsQueryBean.getCustAcctNo() + "对应借据明细信息不存在");
                    throw new BizException("查询借据明细信息" + TRADE_CODE_30230006 + SCENE_NO_07 + "接口查询失败！" + " 客户号：" + repAccLoanDetailsQueryBean.getCustAcctNo());
                }
            } else {
                throw new BizException("贷款借据明细信息查询失败！" + retMsg);
            }
        } catch (Exception e) {

        }
        return respAccLoanDetailsQueryBean;
    }
}
